package cn.wen.javax.servlet.jsp.tagext.builder.form;

import java.util.Map;

import cn.wen.javax.servlet.jsp.tagext.form.InputTag;

public class InputRadioBuilder extends InputBuilder {

    public InputRadioBuilder(InputTag tag) {
	super(tag);
    }

    @Override
    public void process() {
	long id = 0;
	Map<String, String> attrs = tag.getAttrs();
	for (Map<String, ?> option : tag.getOptionList()) {
	    id = System.nanoTime();
	    context.append("<input type=\"radio\" id=\"ui").append(id).append("\" ");
	    if (option.get("value").equals(tag.getValue())) {
		context.append("checked=\"checked\" ");
	    }
	    for (String attr : attrs.keySet()) {
		context.append(attr).append("=\"").append(attrs.get(attr)).append("\" ");
	    }
	    context.append("><label for=\"ui").append(id).append("\">").append(option.get("desc")).append("</label> ");
	}
    }

}
